# -*- coding: utf-8 -*-
from django.shortcuts import render_to_response
from django.template import Context, RequestContext
from django.template.loader import render_to_string as django_render_to_response


def _get_context_instance(request=None):
    if request:
        context_instance = RequestContext(request)
    else:
        context_instance = Context()
    return context_instance


def render(template_name, context, request=None):
    return render_to_response(template_name, context,
        context_instance=_get_context_instance(request))


def render_to_string(template_name, context, request=None):
    return django_render_to_response(template_name, context,
        context_instance=_get_context_instance(request))
